// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Invincibility 2 Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 32 : TYPE_INVINCIBILITY2


// Static Values

// Tables
public table Invincibility2_table24
	7, 4, 6, 4, 4, 6, 4, 7, 4, 6, 6, 4
end table

public table Invincibility2_table23
	2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 3, 4, 5, 6, 7
	6, 5, 4, 3
end table

public table Invincibility2_table22
	1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 2, 3, 4
	5, 6, 7, 6, 5, 4, 3, 2
end table

public table Invincibility2_table21
	0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3
	4, 5, 6, 5, 4, 3, 2, 1
end table


event ObjectMain
	CheckEqual(object[0].state, PlayerObject_HandleMonikaTeleport)
	temp7 = checkResult
	CheckLower(object[0].value1, 20)
	temp7 &= checkResult
	CheckGreater(object[0].value1, 1)
	temp7 &= checkResult
	if temp7 == 0	
		if object.state == 0
			object.value7 = object[-playerCount].xpos
			object.value6 = object[-playerCount].xpos
			object.value5 = object[-playerCount].xpos
			object.value4 = object[-playerCount].xpos
			object.value3 = object[-playerCount].xpos
			object.value2 = object[-playerCount].xpos
			object.value1 = object[-playerCount].xpos
			object.value0 = object[-playerCount].xpos
			object.value15 = object[-playerCount].ypos
			object.value14 = object[-playerCount].ypos
			object.value13 = object[-playerCount].ypos
			object.value12 = object[-playerCount].ypos
			object.value11 = object[-playerCount].ypos
			object.value10 = object[-playerCount].ypos
			object.value9 = object[-playerCount].ypos
			object.value8 = object[-playerCount].ypos
			object.value16 = 180
			object.value17 = 0
			object.state = 1
			object.inkEffect = INK_ALPHA
			object.alpha = 255
			object.drawOrder = -1
		end if
		object.value19++
		object.value19 %= 12
		object.value20++
		object.value20 %= 10
		object.value7 = object.value6
		object.value6 = object.value5
		object.value5 = object.value4
		object.value4 = object.value3
		object.value3 = object.value2
		object.value2 = object.value1
		object.value1 = object.value0
		object.value0 = object[-playerCount].xpos
		object.value15 = object.value14
		object.value14 = object.value13
		object.value13 = object.value12
		object.value12 = object.value11
		object.value11 = object.value10
		object.value10 = object.value9
		object.value9 = object.value8
		object.value8 = object[-playerCount].ypos
		if object[-playerCount].direction == FLIP_NONE
			object.value16 += 144
			object.value16 &= 511
			object.value17 += 16
			object.value17 &= 511
		else
			object.value16 -= 144
			object.value16 &= 511
			object.value17 -= 16
			object.value17 &= 511
		end if
		if object[-playerCount].value7 < 32
			object.alpha = object[-playerCount].value7
			object.alpha <<= 3
		end if
	end if	
end event


event ObjectDraw
	CheckEqual(object[0].state, PlayerObject_HandleMonikaTeleport)
	temp7 = checkResult
	CheckLower(object[0].value1, 20)
	temp7 &= checkResult
	CheckGreater(object[0].value1, 1)
	temp7 &= checkResult
	if temp7 == 0	
		temp2 = object.value17
		temp2 += 116
		Cos(temp0, temp2)
		Sin(temp1, temp2)
		temp0 <<= 11
		temp1 <<= 11
		temp0 += object.value7
		temp1 += object.value15
		GetTableValue(object.frame, object.value19, Invincibility2_table21)
		DrawSpriteFX(object.frame, FX_INK, temp0, temp1)
		temp2 = object.value17
		temp2 += 372
		Cos(temp0, temp2)
		Sin(temp1, temp2)
		temp0 <<= 11
		temp1 <<= 11
		temp0 += object.value7
		temp1 += object.value15
		temp2 = object.value19
		temp2 += 6
		GetTableValue(object.frame, temp2, Invincibility2_table21)
		DrawSpriteFX(object.frame, FX_INK, temp0, temp1)
		Cos(temp0, object.value17)
		Sin(temp1, object.value17)
		temp0 <<= 11
		temp1 <<= 11
		temp0 += object.value5
		temp1 += object.value13
		GetTableValue(object.frame, object.value19, Invincibility2_table22)
		DrawSpriteFX(object.frame, FX_INK, temp0, temp1)
		temp2 = object.value17
		temp2 += 256
		Cos(temp0, temp2)
		Sin(temp1, temp2)
		temp0 <<= 11
		temp1 <<= 11
		temp0 += object.value5
		temp1 += object.value13
		temp2 = object.value19
		temp2 += 6
		GetTableValue(object.frame, temp2, Invincibility2_table22)
		DrawSpriteFX(object.frame, FX_INK, temp0, temp1)
		temp2 = object.value17
		temp2 += 168
		Cos(temp0, temp2)
		Sin(temp1, temp2)
		temp0 <<= 11
		temp1 <<= 11
		temp0 += object.value3
		temp1 += object.value11
		GetTableValue(object.frame, object.value20, Invincibility2_table23)
		DrawSpriteFX(object.frame, FX_INK, temp0, temp1)
		temp2 = object.value17
		temp2 += 424
		Cos(temp0, temp2)
		Sin(temp1, temp2)
		temp0 <<= 11
		temp1 <<= 11
		temp0 += object.value3
		temp1 += object.value11
		temp2 = object.value20
		temp2 += 5
		GetTableValue(object.frame, temp2, Invincibility2_table23)
		DrawSpriteFX(object.frame, FX_INK, temp0, temp1)
		Cos(temp0, object.value16)
		Sin(temp1, object.value16)
		temp0 <<= 11
		temp1 <<= 11
		temp0 += object[-playerCount].xpos
		temp1 += object[-playerCount].ypos
		GetTableValue(object.frame, object.value19, Invincibility2_table24)
		DrawSpriteFX(object.frame, FX_INK, temp0, temp1)
		temp2 = object.value16
		temp2 += 256
		Cos(temp0, temp2)
		Sin(temp1, temp2)
		temp0 <<= 11
		temp1 <<= 11
		temp0 += object[-playerCount].xpos
		temp1 += object[-playerCount].ypos
		DrawSpriteFX(object.frame, FX_INK, temp0, temp1)
	end if	
end event


event ObjectStartup
	LoadSpriteSheet("Global/Items.gif")
	SpriteFrame(0, 0, 1, 1, 18, 126)
	SpriteFrame(0, 0, 1, 1, 19, 126)
	SpriteFrame(-1, -1, 3, 3, 18, 125)
	SpriteFrame(-2, -2, 5, 5, 18, 129)
	SpriteFrame(-3, -3, 7, 7, 18, 135)
	SpriteFrame(-4, -4, 9, 9, 18, 143)
	SpriteFrame(-7, -7, 15, 15, 18, 153)
	SpriteFrame(-15, -15, 31, 31, 18, 169)
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
